<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="java.util.Date"%>
 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
 <c:set var="date" value="<%=new Date() %>"/> 
<fmt:formatDate var ="today" value="${date }" type="date" pattern="yyyyMMdd"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script type="text/javascript" src="/${initParam.context_root }/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/${initParam.context_root }/jquery-ui-1.8.21.custom.min.js"></script>
<link type="text/css" href="/${initParam.context_root }/css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet"></link>
<script type="text/javascript">
	$(document).ready(function(){
		$("#date").datepicker();	
		$("#date").datepicker("option", "dateFormat", "yy-mm-dd");
		$("#date").bind("change",function(){
			var today = ${today};
			var compareToday = window.parseInt(today);
			var saleDate=this.value;
			var inputDate = saleDate.substring(0,4)+saleDate.substring(5,7)+saleDate.substring(8,10);
			if(compareToday<inputDate){
				alert("선택한 구매날짜가 오늘날짜보다 큽니다.\n 다시 선택해 주세요. ");
				return false;
			}
		});
	});

	function chkPriceNum(){
		var pp = modifyForm.productPrice;
		var flagP = window.isNaN(pp.value);
		if(flagP){
			alert("상품가격에 숫자를 입력해 주세요.");
			return false;
		}
	}
	function chkReducedNum(){
		var rp = modifyForm.reducedPrice;
		
		var flagR = window.isNaN(rp.value);
		if(flagR){
			alert("쿠폰가격에 숫자를 입력해 주세요.");
			return false;
		}
	}
	function chkQuantityNum(){
		var q = modifyForm.quantity;
		
		var flagQ = window.isNaN(q.value);
		if(flagQ){
			alert("수량에 숫자를 입력해 주세요.");
			return false;
		}
	}
	function chkInput(){
		var pp = modifyForm.productPrice;
		
		var flagP = window.isNaN(pp.value);
		if(flagP){
			alert("상품가격에 숫자를 입력해 주세요.");
			return false;
		}
		var rp = modifyForm.reducedPrice;
		
		var flagR = window.isNaN(rp.value);
		if(flagR){
			alert("쿠폰가격에 숫자를 입력해 주세요.");
			return false;
		}
		var q = modifyForm.quantity;
		
		var flagQ = window.isNaN(q.value);
		if(flagQ){
			alert("수량에 숫자를 입력해 주세요.");
			return false;
		}
		
		var namechk = modifyForm.productName;
		if(namechk.value==""){
			alert("상품명을 입력해 주세요.");
			return false;
		} 
		if(pp.value==""){
			alert("상품가격을 입력해 주세요.");
			return false;
		}
		if(rp.value==""){
			alert("쿠폰가격을 입력해 주세요.");
			return false;
		}
		if(q.value==""){
			alert("수량을 입력해 주세요.");
			return false;	
		}
		if($("#date").val()==""){
			alert("구매 날짜를 입력해 주세요.");
			return false;	
		}
		
	}
// 	function selectDay(){
// 		window.open("/${initParam.context_root}/jsp/calendar.jsp", "calendar","width=300px, height=300px resizable=no");
// 	}
	
</script>
<br>
<form  name="modifyForm"action="/${initParam.context_root }/modifySale.do" method="post" enctype="multipart/form-data">
<input type="hidden" value="${requestScope.saleDTO.saleNo }" name="saleNo">
<table border=2 cellpadding=10 width=700px>
	<tr>
	<th colspan="2" bgcolor="lightgray">구매내역 직접수정</th>
	</tr>
		<tr>
			<td bgcolor="lightgray" width=100px><b>상품명</b>
			</td>
			<td align="left"><input type="text" value="${requestScope.saleDTO.productName }" name="productName">
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray" width=100px><b>구매사이트</b>
			</td>
			<td align="left">
			<c:choose>
				<c:when test="${requestScope.saleDTO.siteName eq '쿠팡'}">
					<label><input type="radio" name="siteName" checked="checked" value="쿠팡">쿠팡</label>&nbsp;
					<label><input type="radio" name="siteName" value="티몬">티몬</label>&nbsp;
					<label><input type="radio" name="siteName" value="위메프">위메프</label>&nbsp;
					<label><input type="radio" name="siteName" value="그루폰">그루폰</label>&nbsp;
					<label><input type="radio" name="siteName" value="기타">기타</label>&nbsp;
				</c:when>
				<c:when test="${requestScope.saleDTO.siteName eq '티몬'}" >
					<label><input type="radio" name="siteName"  value="쿠팡">쿠팡</label>&nbsp;
					<label><input type="radio" name="siteName"  checked="checked" value="티몬">티몬</label>&nbsp;
					<label><input type="radio" name="siteName" value="위메프">위메프</label>&nbsp;
					<label><input type="radio" name="siteName" value="그루폰">그루폰</label>&nbsp;
					<label><input type="radio" name="siteName" value="기타">기타</label>&nbsp;
				</c:when>
				<c:when test="${requestScope.saleDTO.siteName eq '위메프'}" >
					<label><input type="radio" name="siteName"  value="쿠팡">쿠팡</label>&nbsp;
					<label><input type="radio" name="siteName"   value="티몬">티몬</label>&nbsp;
					<label><input type="radio" name="siteName"  checked="checked" value="위메프">위메프</label>&nbsp;
					<label><input type="radio" name="siteName" value="그루폰">그루폰</label>&nbsp;
					<label><input type="radio" name="siteName" value="기타">기타</label>&nbsp;
				</c:when>
				<c:when test="${requestScope.saleDTO.siteName eq '그루폰'}" >
					<label><input type="radio" name="siteName"  value="쿠팡">쿠팡</label>&nbsp;
					<label><input type="radio" name="siteName"   value="티몬">티몬</label>&nbsp;
					<label><input type="radio" name="siteName" value="위메프">위메프</label>&nbsp;
					<label><input type="radio" name="siteName" checked="checked" value="그루폰">그루폰</label>&nbsp;
					<label><input type="radio" name="siteName" value="기타">기타</label>&nbsp;
				</c:when>
				<c:otherwise>
					<label><input type="radio" name="siteName"  value="쿠팡">쿠팡</label>&nbsp;
					<label><input type="radio" name="siteName" value="티몬">티몬</label>&nbsp;
					<label><input type="radio" name="siteName" value="위메프">위메프</label>&nbsp;
					<label><input type="radio" name="siteName" value="그루폰">그루폰</label>&nbsp;
					<label><input type="radio" name="siteName" checked="checked" value="기타">기타</label>&nbsp;
				</c:otherwise>
			</c:choose>
		</td>
		</tr>
		<tr>
			<td bgcolor="lightgray" width=100px><b>지역</b>
			</td>
			<td align="left">
			<c:choose>
				<c:when test="${requestScope.saleDTO.siteName eq '경기 인천'}" >
					<label><input type="radio" name="location"  value="서울" class="locations">서울</label>&nbsp;
					<label><input type="radio" name="location" value="경기 인천" checked="checked" class="locations">경기,인천</label>&nbsp;
					<label><input type="radio" name="location"  value="부산" class="locations">부산</label>&nbsp;
					<label><input type="radio" name="location" value="강원도" class="locations">강원도</label>&nbsp;
					<label><input type="radio" name="location" value="충청도" class="locations">충청도</label>&nbsp;
					<label><input type="radio" name="location" value="경상도" class="locations">경상도</label>&nbsp;
					<label><input type="radio" name="location" value="전라도" class="locations">전라도</label>&nbsp;
				</c:when>
				<c:when test="${requestScope.saleDTO.siteName eq '부산'}" >
					<label><input type="radio" name="location"  value="서울"  class="locations">서울</label>&nbsp;
					<label><input type="radio" name="location" value="경기 인천" class="locations">경기,인천</label>&nbsp;
					<label><input type="radio" name="location"  value="부산" checked="checked" class="locations">부산</label>&nbsp;
					<label><input type="radio" name="location" value="강원도" class="locations">강원도</label>&nbsp;
					<label><input type="radio" name="location" value="충청도" class="locations">충청도</label>&nbsp;
					<label><input type="radio" name="location" value="경상도" class="locations">경상도</label>&nbsp;
					<label><input type="radio" name="location" value="전라도" class="locations">전라도</label>&nbsp;
				</c:when>
				<c:when test="${requestScope.saleDTO.siteName eq '강원도'}" >
					<label><input type="radio" name="location"  value="서울"  class="locations">서울</label>&nbsp;
					<label><input type="radio" name="location" value="경기 인천" class="locations">경기,인천</label>&nbsp;
					<label><input type="radio" name="location"  value="부산" class="locations">부산</label>&nbsp;
					<label><input type="radio" name="location" value="강원도" checked="checked"class="locations">강원도</label>&nbsp;
					<label><input type="radio" name="location" value="충청도" class="locations">충청도</label>&nbsp;
					<label><input type="radio" name="location" value="경상도" class="locations">경상도</label>&nbsp;
					<label><input type="radio" name="location" value="전라도" class="locations">전라도</label>&nbsp;
				</c:when>
				<c:when test="${requestScope.saleDTO.siteName eq '충청도'}" >
					<label><input type="radio" name="location"  value="서울"  class="locations">서울</label>&nbsp;
					<label><input type="radio" name="location" value="경기 인천" class="locations">경기,인천</label>&nbsp;
					<label><input type="radio" name="location"  value="부산" class="locations">부산</label>&nbsp;
					<label><input type="radio" name="location" value="강원도" class="locations">강원도</label>&nbsp;
					<label><input type="radio" name="location" value="충청도" checked="checked"class="locations">충청도</label>&nbsp;
					<label><input type="radio" name="location" value="경상도" class="locations">경상도</label>&nbsp;
					<label><input type="radio" name="location" value="전라도" class="locations">전라도</label>&nbsp;
				</c:when>
				<c:when test="${requestScope.saleDTO.siteName eq '경상도'}" >
					<label><input type="radio" name="location"  value="서울"  class="locations">서울</label>&nbsp;
					<label><input type="radio" name="location" value="경기 인천" class="locations">경기,인천</label>&nbsp;
					<label><input type="radio" name="location"  value="부산" class="locations">부산</label>&nbsp;
					<label><input type="radio" name="location" value="강원도" class="locations">강원도</label>&nbsp;
					<label><input type="radio" name="location" value="충청도" class="locations">충청도</label>&nbsp;
					<label><input type="radio" name="location" value="경상도" checked="checked"class="locations">경상도</label>&nbsp;
					<label><input type="radio" name="location" value="전라도" class="locations">전라도</label>&nbsp;
				</c:when>
				<c:when test="${requestScope.saleDTO.siteName eq '전라도'}" >
					<label><input type="radio" name="location"  value="서울"  class="locations">서울</label>&nbsp;
					<label><input type="radio" name="location" value="경기 인천" class="locations">경기,인천</label>&nbsp;
					<label><input type="radio" name="location"  value="부산" class="locations">부산</label>&nbsp;
					<label><input type="radio" name="location" value="강원도" class="locations">강원도</label>&nbsp;
					<label><input type="radio" name="location" value="충청도" class="locations">충청도</label>&nbsp;
					<label><input type="radio" name="location" value="경상도" class="locations">경상도</label>&nbsp;
					<label><input type="radio" name="location" value="전라도" checked="checked"class="locations">전라도</label>&nbsp;
				</c:when>
				<c:otherwise >
					<label><input type="radio" name="location"  value="서울" checked="checked" class="locations">서울</label>&nbsp;
					<label><input type="radio" name="location" value="경기 인천" class="locations">경기,인천</label>&nbsp;
					<label><input type="radio" name="location"  value="부산" class="locations">부산</label>&nbsp;
					<label><input type="radio" name="location" value="강원도" class="locations">강원도</label>&nbsp;
					<label><input type="radio" name="location" value="충청도" class="locations">충청도</label>&nbsp;
					<label><input type="radio" name="location" value="경상도" class="locations">경상도</label>&nbsp;
					<label><input type="radio" name="location" value="전라도" class="locations">전라도</label>&nbsp;
				</c:otherwise>
			</c:choose>
		</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>상품가격</b>
			</td>
			<td align="left"><input type="text" value="${requestScope.saleDTO.productPrice }" name="productPrice" maxlength=8 onchange="chkPriceNum()"> 원
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>쿠폰가격</b>
			</td>
			<td align="left"><input type="text" value="${requestScope.saleDTO.reducedPrice}" name="reducedPrice" maxlength=8 onchange="chkReducedNum()"> 원
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>구입(매)수</b>
			</td>
			<td align="left"><input type="text" value="${requestScope.saleDTO.quantity}" name="quantity" maxlength=3 onchange="chkQuantityNum()"> (매)개
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>구매일자</b>
			</td>
			<td align="left"><input type="text" value="${requestScope.saleDTO.saleDate}"   id="date" name="saleDate" readonly="readonly">
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>메모</b>
			</td>
			<td align="left"><textarea cols="40" rows="3" name="memo" >${requestScope.saleDTO.memo }</textarea>
			</td>
		</tr>
		<tr>
			<td bgcolor="lightgray"><b>사진</b>
			</td>
			<td align="left">
			<c:choose>
				<c:when test="${not empty requestScope.saleDTO.productImage }">
					<a href="/${initParam.context_root }/deleteFileSale.do?saleNo=${requestScope.saleDTO.saleNo }">사진삭제</a>
				</c:when>
				<c:otherwise>
					<input type="file" value="찾아보기.." name="upfile">
				</c:otherwise>
			</c:choose>
			</td>
		</tr>
		<tr>
			<td colspan="2">
			<input type="submit" value="수정"> <input type="reset" value="취소"> 
			&nbsp;
			</td>
		</tr>
		</table>
	</form><p>
	<input type="button" value="구매내역 리스트" onclick="location.href='/${initParam.context_root}/selectSaleListByPage.do'">